package MainProgram;

import Algorithms.Pruning;
import java.util.Arrays;

/**
 *
 * @author Zbyszko
 */
public class PruneMain {

    public static void main(String[] args) {

        SinusCreator data = new SinusCreator(100);
        //SimpleDataCreator data = new SimpleDataCreator();

        int update = 0;
        double maxAcceptableError = 1e-6;
        
        Pruning prune = new Pruning(data.getTrainingSet(),
                data.getDesiredOutput(), maxAcceptableError);
        prune.startIncremental();

        while (!prune.isDone()) {
            prune.pruneIncremental();
            update++;
            if (update == 1000) {
                System.out.println("Hidden Neurons:" + prune.getHiddenNeuronCounter()
                        + ", Current Error=" + prune.getError());
                update = 0;
            }
            
            if(prune.getHiddenNeuronCounter() >= 100) {
                System.out.println("FAILURE!");
                break;
            }
        }

        String units = Arrays.toString(prune.getNetwork().getNeuronsInHiddenLayers());
        Plot plot = new Plot(
                "Neural Network", //window title 
                "Incremental Prunning with " + units + " hidden units", //plot title
                data.getTrainingSet(), //training set 
                data.getDesiredOutput(), //desired output
                Main.printFinalResults(prune.getNetwork()) //obtained result
                );
        plot.setVisible(true);
        System.out.println("RMSE: " + prune.getNetwork().calculateRMSE());
    }
}
